home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Skunkware 5
/
Skunkware 5.iso
/
src
/
X11
/
lib
/
misc.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-05-03
|
1KB
|
62 lines
/* routines to center a window on a screen.
* center_vertical() takes as arguments a display, window and window height.
* it reconfigures the window to be centered vertically.
*/
#include <X11/Xlib.h>
void
center_vertical(dpy, w, height)
Display *dpy;
Window w;
int height;
{
Window root, child;
int top, x, y, rootX, rootY;
unsigned int bw, d, new_w, new_h;
XWindowChanges values;
XGetGeometry(dpy,w,&root,&x,&y,&new_w,&new_h,&bw,&d);
XTranslateCoordinates(dpy, w, root, 0, 0, &rootX, &rootY, &child);
top = XDisplayHeight(dpy, DefaultScreen(dpy)) - height;
y = (top/2) - rootY;
if (y < 0)
y = -y;
if (y > 0) {
values.y = (top - (2*y)) / 2,0;
if (values.y < 0)
values.y = 0;
XConfigureWindow(dpy,w,CWY,&values);
}
}
/*
* center_horizontal() takes as arguments a display, window and window width.
* it reconfigures the window to be centered horizontally.
*/
void
center_horizontal(dpy, w, width)
Display *dpy;
Window w;
int width;
{
Window root, child;
int left, x, y, rootX, rootY;
unsigned int bw, d, new_w, new_h;
XWindowChanges values;
XGetGeometry(dpy,w,&root,&x,&y,&new_w,&new_h,&bw,&d);
XTranslateCoordinates(dpy, w, root, 0, 0, &rootX, &rootY, &child);
left = XDisplayWidth(dpy, DefaultScreen(dpy)) - width;
x = (left/2) - rootX;
if (x < 0)
x = -x;
if (x > 0) {
values.x = (left - (2*x)) / 2, 0;
if (values.x < 0)
values.x = 0;
XConfigureWindow(dpy,w,CWX,&values);
}
}